
/* File name	: test.c
 * Project 		: BKIT MCR
 * Version 		: 1.0
 * Creation Date: 07/07/2010
 * Tabsize		: 4
 * Author  		: BKIT4U                   
 * Copyright	: (c) 2010 BKIT HARDWARE CLUB - www.bkit4u.com
 * License		: Free.
 * Comments		: 
 * 
 */

/*====================================*/
/*  Include                           */
/*====================================*/
#include <util/delay.h>
#include "test.h"

#include "../input/input.h"
#include "../handle/handle.h"
#include "../speed/speed.h"
#include "../led/led.h"
#include "../timer/timer.h"
#include "../adc/adc.h"
#include "../beep/beep.h"


/*====================================*/
/*  Function name: test               */
/*  Parameter: null                   */
/*  Description: to implement cases   */
/*              to test all modules   */
/*              on BKIT MCR car       */
/*====================================*/
void test(){
	unsigned char i=0;
	unsigned char K0,K1,K2,K3,KX;

	while(1){
		K3 = get_key(KEY3);
		K2 = get_key(KEY2);
		K1 = get_key(KEY1);
		K0 = get_key(KEY0);
		KX = get_extkey();

		if(KX) {	// press the key in power board to run
			handle(0);
			break;	
		}		

		switch(dipsw_input){
		case 0:					
			/*************save sensor************/
			led7_putHex(0x00);
			if (K0|K1|K2|K3){	// press any key to save sensor value
				i = 0;		
				while(i++ < 10)
				{
					save_sensor(WHITE);
					led7_putHex(i);
					_delay_ms(20);
				}
				led7_putHex(0xff);
				_delay_ms(2000);
			}
			break;
		case 1:					
			/************test DC motor***********/
			led7_putHex(0x01);
			if (K0){			// press KEY0 to run left motor backward 
				speed(-100,0);
				_delay_ms(10);
			}else if(K1){		// press KEY1 to run left motor forward 
				speed(100,0);
				_delay_ms(10);
			}else if(K2){		// press KEY2 to run right motor backward 
				speed(0,-100);
				_delay_ms(10);
			}else if(K3){		// press KEY3 to run right motor forward 
				speed(0,100);
				_delay_ms(10);
			}else{				// stop
				speed(0,0);
			}
			break;
		case 2:
			/************test RC servo***********/
			led7_putHex(0x02);
			if (K0){			// press KEY0 to turn right
				handle_center += 10;
				handle(0);
				_delay_ms(50);
			}else if(K3){	// press KEY3 to turn left
				handle_center -= 10;
				handle(0);
				_delay_ms(50);
			}
			else if (K1||K2)
			{
				save_handle_center ();
				_delay_ms(1000);
				beep_long(200);
				_delay_ms(200);
			}
			break;
		case 3: 
			led7_putHex(0x03);
			break;
		case 4: 
			led7_putHex(0x04);
			break;
		case 5:
			led7_putHex(0x05);
			break;
		case 6:
			led7_putHex(0x06);		
			break;
		case 7: 
			led7_putHex(0x07);
			break;
		case 8:
			led7_putHex(0x08);
			break;
		case 9:
			led7_putHex(0x09);
			break;
		case 10:
			led7_putHex(0x10);
			break;
		case 11:
			led7_putHex(0x11);
			break;
		case 12:
			led7_putHex(0x12);
			break;
		case 13:
			led7_putHex(0x13);
			break;
		case 14:
			led7_putHex(0x14);
			break;
		case 15:
			led7_putHex(0x15);
			break;
		default:
			
			break;
		}	
	}
}


/****************END FILE**************/

